package com.ruoyi.web.controller.app.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.exception.base.XException;
import com.ruoyi.im.domain.User;
import com.ruoyi.im.mapper.UserMapper;
import com.ruoyi.sj.domain.WqEweiShopMember;
import com.ruoyi.sj.mapper.WqEweiShopMemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName CustomerService
 * @Description TODO
 * @Author tyc@yanyu
 * @Date 2018/12/7 0007 10:48
 **/
@Service
public class AppCustomerService {
    @Autowired
    private WqEweiShopMemberMapper wqEweiShopMemberMapper;
    @Autowired(required = false)
    private UserMapper userMapper;//用户mapper

    /**
     * 查询用户信息
     *
     * @param openid
     * @return
     */
    public Object queryCustomer(String openid) {
        if (StringUtils.isBlank(openid)) {
            throw new XException("openid不能为空");
        }
        WqEweiShopMember shopMember = wqEweiShopMemberMapper.queryCustomerByOpenid(openid);
        if (shopMember != null) {
            User user = userMapper.selectUserByMemberId(shopMember.getOpenid());
            shopMember.setIMID(user.getId());
        }
        return shopMember;
    }
}
